public class Num6 {

    public String convert(String s, int numRows) {
        if (numRows <= 1){
            return s;
        }

        StringBuilder res = new StringBuilder();

        for (int i = numRows; i > 0; i--){
            // 空位在左
            int k = 0;
            for (int j = numRows - i; j < s.length();){
                res.append(s.charAt(j));
                if (i == numRows || i == 1){
                    j = j + (numRows - 1) * 2;
                } else {
                    if (k == 0){
                        j = j + (i - 1) * 2;
                        // 右侧
                        k = 1;
                    } else {
                        j = j + (numRows - i) * 2;
                        // 左侧
                        k = 0;
                    }
                }
            }
        }

        return res.toString();

    }

    public static void main(String[] args) {
        String s = "LEETCODEISHIRING";
        int numRows = 4;
        Num6 num6 = new Num6();

        String res = num6.convert(s, numRows);
        System.out.println(res);
    }
}
